package cn.zyq.demo.service.sys.impl;


import cn.zyq.demo.beans.sys.SysAdmin;
import cn.zyq.demo.beans.sys.SysRoleDept;
import cn.zyq.demo.mapper.sys.SysRoleDeptMapper;
import cn.zyq.demo.service.sys.SysRoleDeptService;
import cn.zyq.demo.system.common.BaseService;
import cn.zyq.demo.system.common.PageParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 角色和部门关联表
 * 2023-05-12 20:14:09
 */

@Slf4j
@Service
public class SysRoleDeptServiceImpl extends BaseService implements SysRoleDeptService {
    @Autowired
    private SysRoleDeptMapper sysRoleDeptMapper;


    @Override
    public PageInfo<SysRoleDept> list(PageParam pageParam, SysAdmin admin) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        List<SysRoleDept> dbList = this.sysRoleDeptMapper.list(pageParam.getKv());
        return new PageInfo<>(dbList);
    }

    @Override
    public void add(SysRoleDept param, SysAdmin admin) {
        this.setCreateBaseData(param, admin);
        this.sysRoleDeptMapper.insertSelective(param);
    }

    @Override
    public void update(SysRoleDept param, SysAdmin admin) {
        Integer id = param.getSysRoleDeptID();
        this.setUpdateBaseData(param, admin);
        this.sysRoleDeptMapper.updateByPrimaryKeySelective(param);
    }

    @Override
    public void del(String serviceID, SysAdmin admin) {
        SysRoleDept dbInfo = this.detail(serviceID);
        Integer id = dbInfo.getSysRoleDeptID();
        this.deleteLogic(id, admin, this.sysRoleDeptMapper);
    }

    @Override
    public SysRoleDept detail(String serviceID, SysAdmin admin) {
        return this.detail(serviceID);
    }

    @Override
    public SysRoleDept detail(String serviceID) {
        SysRoleDept dbInfo = this.getByServiceID(serviceID, SysRoleDept.class, this.sysRoleDeptMapper);
        this.checkLogicExist(dbInfo);
        return dbInfo;
    }
}
